// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Up Down Block Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 9 : TYPE_UPDOWNBLOCK

// Function declarations
reserve function UpDownBlock_DebugDraw
reserve function UpDownBlock_DebugSpawn

// Static Values
public value UpDownBlock_value14 = 0;

// Tables

function UpDownBlock_DebugDraw
	temp4 = object[0].value10
	temp4 -= UpDownBlock_value14
	DrawSprite(temp4)
end function


function UpDownBlock_DebugSpawn
	temp4 = object[0].value10
	temp4 -= UpDownBlock_value14
	temp5 = 9
	CallFunction(DebugMode_SpawnObject)
	object[arrayPos0].drawOrder = 4
	object[arrayPos0].groupID = GROUP_BLOCKS
end function


event ObjectMain
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CallFunction(SpecialSetup_Function10)
		if checkResult != 0
			if object[currentPlayer].value15 == 0
				object[currentPlayer].value15 = 30
				if object.propertyValue == 0
					if PlayerObject_value2 < 1
						PlayerObject_value2++
						object.propertyValue = 1
						PlaySfx(SfxName[Rotate Block], 0)
					end if
				else
					if PlayerObject_value2 > 0
						PlayerObject_value2--
						object.propertyValue = 0
						PlaySfx(SfxName[Rotate Block], 0)
					end if
				end if
			end if
		end if
	next
end event


event ObjectDraw
	CallFunction(SpecialSetup_Function9)
	temp2 = oscillation
	temp2 &= 15
	temp2 >>= 3
	if temp2 == 0
		DrawSpriteXY(object.propertyValue, temp0, temp1)
	else
		DrawSpriteXY(2, temp0, temp1)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 226, 76)
	SpriteFrame(-12, -12, 24, 24, 226, 176)
	SpriteFrame(-12, -12, 24, 24, 251, 76)
	foreach (TypeName[Up Down Block], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].groupID = GROUP_BLOCKS
	next
	UpDownBlock_value14 = DebugMode_ObjCount
	SetTableValue(TypeName[Up Down Block], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(UpDownBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(UpDownBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
	SetTableValue(TypeName[Up Down Block], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(UpDownBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(UpDownBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(object.propertyValue)
end event

event RSDKLoad
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-12, -12, 24, 24, 226, 76)
	SpriteFrame(-12, -12, 24, 24, 226, 176)
	SpriteFrame(-12, -12, 24, 24, 251, 76)
end event
